// 分析报告导出
import * as htmlToImage from "html-to-image";
import { chartImgBase64 } from "@/utils/utils";
export default {
  methods: {
    analysisExport() {
      let _this = this;
      const query = _this.$route.query;
      if (!query.export) {
        return;
      }
      const idDom = document.getElementById("chart-tab");
      setTimeout(() => {
        if (idDom) {
          htmlToImage.toPng(idDom).then(function(dataurl) {
            // console.log("dataurl", dataurl);
            _this.updateAnalysisCacheData(dataurl, query);
          });
        } else {
          _this.updateAnalysisCacheData("", query);
        }
      }, 2000);
    },
    updateAnalysisCacheData(dataurl, query) {
      const chartImg = chartImgBase64(this.dom) || "";
      let param = {
        postResult: JSON.stringify(this.dcData),
        postJson: "",
        echartsImg: chartImg,
        tableImg: dataurl,
        historyid: parseInt(query.historyId),
        code: query.tempId + "",
      };
      // console.log("param11111", param);
      this.$post(this.$Url.analysis.updateAnalysisCacheData, param).then(
        (res) => {
          // console.log("------", res.data);
        }
      );
    },
  },
};
